package news.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.whu.administrator.ws.R;
import com.whu.administrator.ws.UIHandler;

import org.w3c.dom.Text;

import inter.Delegate;
import inter.ResponseStatus;
import news.dto.NotifyMessages;
import news.network.GetDetailNew;
import news.network.GetNewNotify;

/**
 * 详细新闻
 * Created by Administrator on 2016/3/23.
 */
public class DetailNewsActivity extends UIHandler.BaseActivity {

    String notify_ID;
    NotifyMessages notifyMessages = new NotifyMessages();

    TextView tv_time;
    TextView tv_author;
    TextView tv_title;
    TextView tv_digest;
    TextView tv_content;

    GetDetailNew getDetailNew = new GetDetailNew();

    Delegate DetailData = new Delegate() {
        @Override
        public void onResponse(String response) {
            if (!response.startsWith("{")) return;
            Gson gson = new Gson();
            GetDetailNew.ResponseDetailNotify responseDetailNotify = gson.fromJson(response, GetDetailNew.ResponseDetailNotify.class);
            if (responseDetailNotify.getStatus().equals(ResponseStatus.SUCCESS))
            {
                notifyMessages = responseDetailNotify.getMessage();
                setData(notifyMessages);
            }

        }

        @Override
        public void onErrorResponse(VolleyError error) {

        }
    };

    {
        getDetailNew.setDelegate(DetailData);
    }

    // 给界面设置数据
    private void setData(NotifyMessages notifyMessages) {
        tv_time.setText(notifyMessages.getNotify_Time());
        tv_author.setText(notifyMessages.getNotify_Author());
        tv_title.setText(notifyMessages.getNotify_Title());
        tv_digest.setText(notifyMessages.getNotify_Digest());
        tv_content.setText(notifyMessages.getNotify_Content());
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detailnew);
        initview();
        initdata();
    }

    private void initdata() {
        Intent intent = getIntent();
        notify_ID = intent.getStringExtra("notify_ID");
        getDetailNew.setNew_id(notify_ID);
        getDetailNew.get();
    }

    private void initview() {
        tv_time = (TextView) findViewById(R.id.id_tv_time);
        tv_author = (TextView) findViewById(R.id.id_tv_author);
        tv_title = (TextView) findViewById(R.id.id_tv_title);
        tv_content = (TextView) findViewById(R.id.id_tv_content);
        tv_digest = (TextView) findViewById(R.id.id_tv_Digest);


    }
}
